package gemini.castor.ui.client.page.content.home.register;

import com.google.gwt.event.shared.GwtEvent;

public class RegisterEvent extends GwtEvent<RegisterHandler> {

	private static Type<RegisterHandler> TYPE;
	
	public static Type<RegisterHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<RegisterHandler>();
		return TYPE;
	}
	
	public enum ForwardType {
		SUBMIT,CANCEL,REGISTER,RESET,CONFIRM,BACK;
	}
	
	public RegisterEvent(ForwardType forwardType) {
		super();
		this.setForwardType(forwardType);
	}
	
	private ForwardType forwardType;

	@Override
	protected void dispatch(RegisterHandler handler) {
		if(forwardType.equals(ForwardType.SUBMIT)){
			handler.onSubmit(this);
		}else if(forwardType.equals(ForwardType.REGISTER)){
			handler.onRegister(this);
		}else if(forwardType.equals(ForwardType.CANCEL)){
			handler.onCancel(this);
		}else if(forwardType.equals(ForwardType.BACK)){
			handler.onBack(this);
		}else if(forwardType.equals(ForwardType.CONFIRM)){
			handler.onConfirm(this);
		}
		
	}
	
	@Override
	public Type<RegisterHandler> getAssociatedType() {
		return getType();
	}

	public void setForwardType(ForwardType forwardType) {
		this.forwardType = forwardType;
	}

	public ForwardType getForwardType() {
		return forwardType;
	}
}
